﻿package cn.poco.pepsi.activity;


import cn.poco.pepsi.constants.Constants;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.KeyEvent;

public class BaseActivity extends Activity {

	private Boolean flag = true;	//判断返回事件源
	
	
	//子类重写刷新方法
	protected void refurbish(){
		
	}

	@Override	//捕获返回事件
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode==KeyEvent.KEYCODE_BACK && getFlag()){
			new AlertDialog.Builder(this)
			.setTitle("是否退出")
			.setMessage("退出美食天堂")
			.setPositiveButton("退出", new OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					Constants.exit = "stop";
					finish();
				}
			})
			.setNegativeButton("取消", null).show();
			return true;
		}else{
			return super.onKeyDown(keyCode, event);
		}
		
	}
	public Boolean getFlag() {
		return flag;
	}
	public void setFlag(Boolean flag) {
		this.flag = flag;
	}
	
	
	
	
	   
	
	
	
}
